package my.object.compare;

import java.util.Comparator;

public final class PhoneNumber implements Comparable<PhoneNumber> {
    private short areaCode, prefix, lineNum;

    private Comparator<PhoneNumber> comparator = Comparator.comparingInt((PhoneNumber pn) -> pn.areaCode)
            .thenComparingInt(pn -> pn.prefix) //此处不用传入(PhoneNumber pn)类型
            .thenComparingInt(pn -> pn.lineNum);

    @Override
    public int compareTo(PhoneNumber pn) {
        Object o = new Object();
        //千万不要 o.hashCode()-o.hashCode() 这样做 很容易造成整数的溢出 例如  2147483648 -(-2147483648)
        return comparator.compare(this, pn);
    }
}
